package com.philosophy.web.service.impl;

import com.philosophy.web.cmd.DeleteUrlMappingCmd;
import com.philosophy.web.domain.generate.UrlMapping;
import com.philosophy.web.filter.RedirectFilter;
import com.philosophy.web.repository.ShortUrlRepository;
import com.philosophy.web.service.ShortUrlService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author philosophy
 */
@Service
public class ShortUrlServiceImpl implements ShortUrlService {

    @Resource
    private ShortUrlRepository shortUrlRepository;
    @Resource
    private RedirectFilter redirectFilter;

    @Override
    public String createUrlMapping(String originUrl) {
        UrlMapping urlMapping = shortUrlRepository.save(originUrl);
        String shortUrl = urlMapping.getShortUrl();
        //放入布隆过滤器
        redirectFilter.putBloomFilter(shortUrl);
        return shortUrl;
    }

    @Override
    public String deleteUrlMapping(DeleteUrlMappingCmd deleteUrlMappingCmd) {
        return null;
    }
}
